from GetInput import *


class MenuUI:
    def __init__(self, name, action=None):
        self.name = name
        self.action = action
        self.__menuList = []
    def execute(self, ):
        if self.action == None:
            while True:
                print("")
                self.__showMenuList()
                print("")
                index = inputValidNumberRange("CHOOSE AN OPERATION: ", 0, len(self.__menuList))                
                if index == 0:
                    break
                self.__menuList[index - 1].execute();
        else :
            self.action()
    def addSubMenu(self, subMenu):
        self.__menuList.append(subMenu)
    def __delSubMenu(self, index):
        pass
    def __showMenuList(self):
        i = 1
        for menu in self.__menuList:
            print("(%d) %s"%(i, menu.name))
            i = i + 1
        print("(0) BACK/EXIT")
    def __getInput(self):
        inStr = input("CHOOSE AN OPERATION: ")
        try:
            index = int(inStr)
        except:
            return None
        return index
